package com.chutoutian.untils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.PropertyFilter;
import com.alibaba.fastjson.serializer.SerializerFeature;

public class JSONUtil {

    private static String Y_M_D_H = "yyyy-MM-dd HH:mm:ss";
    private static String Y_M_D = "yyyy-MM-dd";

    public static String toJSONString(Object object) {
        return toJSONString(object, Y_M_D_H, null);
    }


    public static String toJSONString(Object object, String dataFarmat, PropertyFilter propertyFilter) {
        if (Y_M_D.equals(dataFarmat)) {
            JSON.DEFFAULT_DATE_FORMAT = Y_M_D;
        } else if (Y_M_D_H.equals(dataFarmat)) {
            JSON.DEFFAULT_DATE_FORMAT = Y_M_D_H;
        }
        return JSON.toJSONString(object, propertyFilter, SerializerFeature.WriteDateUseDateFormat, SerializerFeature.SortField);
    }

}
